////////////////////////////////////////////////////////////////////////////////
//
//	This file is part of Woozox, see <http://code.google.com/p/woozox/>.
//
//	Copyright 2008-2009 Florian David
//
//	Woozoo is free software: you can redistribute it and/or modify
//	it under the terms of the GNU Lesser General Public License as 
//	published by the Free Software Foundation, either version 3 of 
//	the License, or (at your option) any later version.
//
//	Woozoo is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//	GNU General Public License for more details.
//
//	You should have received a copy of the GNU Lesser General Public 
//	License along with Woozoo. If not, see <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
package org.woozoo.xhtml.extended.base
{
	import org.woozoo.xhtml.core.base.*;
	import org.woozoo.xhtml.core.manager.element.ElementManager;

	/**
	 * Extended Document to easily get images, links, videos and swfs.
	 * */
	public class EXDocument extends Document
	{
		/**
		 * @private
		 * */
		protected var _videos : Array = null; /* of VideoElement */

		/**
		 * @private
		 * */
		protected var _swfs : Array = null; /* of SwfElement */

		/**
		 * @private
		 * */
		protected var _images : Array = null; /* of ImgElement */

		/**
		 * @private
		 * */
		protected var _links : Array = null; /* of LinkElement */

		/**
		 * 
		 * */
		public function EXDocument(name:String, url:String, source:*=null)
		{
			super(name, url, source);
		}
		
		/**
		 * The list of ImgElement of your document.
		 * 
		 * @see ImgElement
		 * */
		public function get images() : Array /* of ImgElement */ {
			if (!_images) {
				_images = getElementsByTagName('img');
			}
			return _images;
		}

		/**
		 * The list of VideoElement of your document.
		 * 
		 * @see VideoElement
		 * */
		public function get videos() : Array /* of VideoElement */ {
			if (!_videos) {
				var res : Array = []
				var list : Array = getElementsByTagName('object');
				var len : int = list.length;
				for (var i : int = 0; i < len; i++) {
					var object : Element = list[i];
					var param : Element = object.getElementsByTagName('param', 1, 1)[0];
					if (param.att('name') == "movie") {
						res.push(ElementManager.getInstance().create(this, object, VideoElement));
					}
				}
				_videos = res;
			}
			return _videos;
		}
		
		/**
		 * The list of SwfElement of your document.
		 * 
		 * @see SwfElement
		 * */
		public function get swfs() : Array /* of SwfElement */ {
			if (!_swfs) {
				var res : Array = []
				var list : Array = getElementsByTagName('object');
				var len : int = list.length;
				for (var i : int = 0; i < len; i++) {
					var object : Element = list[i];
					var param : Element = object.getElementsByTagName('param', 1, 1)[0];
					if (param.att('name') == "src") {
						res.push(ElementManager.getInstance().create(this, object, SwfElement));
					}
				}
				_swfs = res;
			}
			return _swfs;
		}
		
		/**
		 * The list of LinkElement of your document.
		 * 
		 * @see LinkElement
		 * */
		public function get links() : Array /* of LinkElement */ {
			if (!_links) {
				_links = getElementsByTagName('a');
			}
			return _links;
		}
	}
}